#include "lc_sort_Operator.h"
#include <algorithm>

bool sortPred(const boost::shared_ptr<std::string>& d1, const boost::shared_ptr<std::string>& d2)
{
  return (*d1) < (*d2);
}

void 
sort::new_word(StringWrapper * data, unsigned long dataSize)
{
  if(data->token) {
    std::sort(wordList.begin(), wordList.end(), sortPred);
    for(std::vector<boost::shared_ptr<std::string> >::iterator iter = wordList.begin();
	iter != wordList.end(); iter++) {
      boost::shared_ptr<std::string> word = *iter;
      StringWrapper *temp = new StringWrapper();
      temp->coreString = word;
      out(temp, sizeof(temp));
    }
    StringWrapper *temp = new StringWrapper();
    temp->token = true;
    out(temp, sizeof(temp));
  }
  else {
    wordList.push_back(data->coreString);
  }
  delete data;
}

StringWrapper * 
sort::geninRequest() 
{
  return NULL;
}

void 
sort::my_install(void * data) 
{}

void * 
sort::my_get()
{return NULL;}

void 
sort::my_purge(void * data)
{}

void 
sort::my_init()
{}
